﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace WindowsGame1
{
    class DataVector
    {

        #region protected variables
        /// <summary>
        /// position of Vector
        /// </summary>
        protected Vector2 _position;
        /// <summary>
        /// pressure value from Vector, -1000 = 0
        /// </summary>
        protected float _pressure;

        /// <summary>
        /// direction 
        /// </summary>
        protected Vector2 _direction;
        /// <summary>
        /// timestep in which the Vector is located
        /// </summary>
        protected int _timeStep;
        protected bool _directionIsCalculated = false;

        protected Vectorfield _parentVectorfield;
        #endregion

        #region constructors
        /// <summary>
        /// Vector with all the Data we have / need
        /// </summary>
        /// <param name="position">the position</param>
        public DataVector(Vectorfield parent)
        {
            _position = new Vector2(0,0);
            _pressure = 0;
            _timeStep = 0;
            _direction = new Vector2(0, 0);
            _parentVectorfield = parent;
        }

        /// <summary>
        /// empty placeholder Datavector
        /// </summary>
        public DataVector()
        {
            _position = new Vector2(0,0);
            _pressure = 0;
            _timeStep = 0;
            _direction = new Vector2(0, 0);
            _parentVectorfield = null;
        }
        #endregion

        #region properties

        /// <summary>
        /// gets or sets the position vector
        /// </summary>
        public Vector2 position
        {
            get
            {
                return _position;
            }
            set
            {
                _position = value;
            }
        }
        /// <summary>
        /// gets or sets the pressure value; -1000 set to 0
        /// </summary>
        public float pressure
        {
            get
            {
                return _pressure;
            }
            set
            {
                if (value != -1000)
                {
                    _pressure = value;
                }
                else
                    _pressure = 0;
            }
        }

        /// <summary>
        /// gets or sets the direction
        /// </summary>
        public Vector2 direction
        {
            //if direction of vector hasn't been calculated yet-> only calculate if needed
            get
            {
                if (!_directionIsCalculated)
                {
                    _directionIsCalculated = true;
                    _direction = _parentVectorfield.CalculateDirection(this.position);
                }
                return _direction;
            }

            set
            {
                _direction = value;
            }
        }

        public int timestep
        {
            get 
            {
                return _timeStep;
            }
            set
            {
                _timeStep = value;
            }
        }
        #endregion
    }
}
